/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.chiefmedicalofficer.mcd.model;

import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDFS;

/**
 *
 * @author twilson
 */
public class SparqlGenerator {

    static String subPropertyOf = RDFS.subPropertyOf.getURI();
    static String label = RDFS.label.getURI();
    static String domain = RDFS.domain.getURI();
    static String title = DC.title.getURI();

    /**
     * For a given node, get the predicate and object of every triple
     * for which it is the subject. Include DC:title
     *
     */
    public static String getObjectProperties(String subjectUri) {
        return "SELECT ?pred ?predTitle ?predLabel ?parentPred ?obj ?objTitle \n" +
            "WHERE {<" + subjectUri + "> ?pred ?obj . \n" +
            "OPTIONAL {?pred <" + title + "> ?predTitle} . \n" +
            "OPTIONAL {?pred <" + label + "> ?predLabel} . \n" +
            "OPTIONAL {?pred <" + subPropertyOf + "> ?parentPred} . \n" +
            "OPTIONAL {?obj <" + title + "> ?objTitle} } \n";
    }

    /**
     * For a given node, return the subject and predicate of every triple
     * for which it is the object. Include DC:title
     *
     */
    public static String getSubjectProperties(String objectUri) {
        return "SELECT ?subj ?subjTitle ?pred ?predTitle ?predLabel ?parentPred \n" +
            "WHERE { ?subj ?pred <" + objectUri + "> . \n" +
            "OPTIONAL {?pred <" + title + "> ?predTitle} . \n" +
            "OPTIONAL {?pred <" + label + "> ?predLabel} . \n" +
            "OPTIONAL {?pred <" + subPropertyOf + "> ?parentPred} . \n" +
            "OPTIONAL {?subj <" + title + "> ?subjTitle} } \n";
    }

    /**
     * Get assignable predicates for a given class. Include predicate label.
     * Also include parent node, so we can return this in a tree structure
     * of sub-properties. Include RDFS:label
     *
     **/
    public static String getPredicates(String classUri) {
        return " \n" +
"SELECT ?prop ?label ?parent \n" +
"WHERE { ?prop <" + domain + "> <" + classUri + "> . \n" +
"   OPTIONAL {  ?prop <" + label + "> ?label } . \n" +
"   OPTIONAL {  ?prop <" + subPropertyOf + "> ?parent } }  \n";
    }
}
